package db;

import tool.Arrays;

public class ArtistRecord {

	private static final int NO_RECORD = -1;
	private String artist;
	private Mp3DBRecord[] mp3Records;
	private int lastIndex = NO_RECORD;

	public ArtistRecord(String anArtist) {
		artist = anArtist;
		mp3Records = new Mp3DBRecord[100];
		Arrays.initialize(mp3Records);
	}

	public void addMP3Record(Mp3DBRecord record) {
		if (lastIndex == NO_RECORD) {
			lastIndex = 0;
		} else {
			lastIndex++;
		}
		mp3Records[lastIndex] = record;
	}

	public Mp3DBRecord[] getRecords() {
		return getTrimRecords();
	}

	private Mp3DBRecord[] getTrimRecords() {
		int i = 0;
		
		while ((mp3Records[i] != null) && (i < mp3Records.length))  {
			i++;
		}
		Mp3DBRecord[] result = new Mp3DBRecord[i];
		
		for (int j = 0; j < result.length; j++) {
			result[j] = mp3Records[j];
		}
		return result;
	}

	public String getArtistName() {
		return artist;
	}

}
